
import React, { useState, useEffect } from 'react';
import { Form, Input, InputNumber, Button } from 'antd';
import { BasicDiv } from './style'
import { LineOutlined } from '@ant-design/icons';
import { getStorage, setStorage } from '@/utils/LocalStorage.js'
import { useHistory } from 'react-router-dom';
const layout = {
    labelCol: {
        span: 8,
    },
    wrapperCol: {
        span: 10,
    },
};
const Index = () => {
    const history = useHistory()
    const [data, setData] = useState({})
    let datalist = getStorage('users') ? JSON.parse(getStorage('users')) : []
    const onFinish = (values) => {
        setData({
            ...values.user,
            key: Date.now(),
        })
        history.push("/home/supplier")
    }
    useEffect(() => {
        if (JSON.stringify(data) === "{}") {
            return false
        } else {
            datalist = [...datalist, data]
            setStorage('users', JSON.stringify(datalist))
        }
    });
    return (

        <BasicDiv>
            <div className='masage'>
                <LineOutlined rotate={90} style={{ color: 'red', fontSize: '20px' }} /> 发起信息
             </div>
            <Form {...layout} name="nest-messages" onFinish={onFinish}>
                <div className="sponsor">
                    <Form.Item
                        name={['user', 'name']}
                        label="引进负责人"
                        rules={[
                            {
                                required: false,
                            },
                        ]}
                    >
                        <Input />
                    </Form.Item>
                    <Form.Item
                        name={['user', 'rootIn']}
                        label="供应商来源"
                    >
                        <Input />
                    </Form.Item>

                    <Form.Item name={['user', 'numbering']} label="产品编号">
                        <Input />
                    </Form.Item>
                </div>
                <div className='masage'>
                    <LineOutlined rotate={90} style={{ color: 'red', fontSize: '20px' }} /> 公司信息
            </div>
                <div className="relation">
                    <Form.Item
                        name={['user', 'compony']}
                        label="单位名称"
                        rules={[
                            {
                                required: false,
                            },
                        ]}
                    >
                        <Input />
                    </Form.Item>
                    <Form.Item
                        name={['user', 'logo']}
                        label="品牌"
                    >
                        <Input />
                    </Form.Item>

                    <Form.Item name={['user', 'scope']} label="经营范围">
                        <Input />
                    </Form.Item>
                    <Form.Item wrapperCol={{ ...layout.wrapperCol, offset: 10 }}>
                        <Button style={{ marginRight: '20px' }}>
                            取消
                    </Button>
                        <Button type="primary" htmlType="submit">
                            保存
                        </Button>
                    </Form.Item>
                </div>
            </Form>
        </BasicDiv>
    );
}

export default Index;
